<?php
	
	include_once 'autoload.php';
	
	session_start();

	$ctl = new UsersCtl();
	$ctl->checkAdmin();
	$ctl->checkNotReadonly();
	$ctl->proceed();
	
	$header = new Header();
	$header->render('Users');

	$form = $ctl->getUsersForm();
	
	$selected = $form->getSelected();
	$users = $form->getUsers();
	
	
?>
<form method="post">
<input type="hidden" name="pagename" value="users" id="pgid">
<input type="hidden" name="metname" value="" id="metid">
<input type="hidden" name="idedit" value="" id="idedit">

<h2>Users</h2>
<div style="width: 450px; margin-bottom: 10px;">This is the list with
currently configured users. You can add a new one, change user password,
change the access rights or change the user informaton alltogether.
Please proceed by accessing the controls below</div>
<table cellspacing="0" cellpadding="6" class="list">
	<thead>
		<tr>
			<td>Select</td>
			<td>Name</td>
			<td>Login</td>
			<td><div align="center">Connect</div></td>
			<td><div align="center">Admin</div></td>
			<td>Email</td>
			<td><div align="center">Send Email</div></td>
			<td>Password</td>
		</tr>
	</thead>
	<tbody>
<?php
	$i = 0;
	
	foreach($users as $current){
		$i ++;
		$class = $i % 2 == 0 ? 'even' : 'odd';
		
		$id = $current->getId();
		
		$name = htmlspecialchars($current->getName());
		$login = htmlspecialchars($current->getLogin());
		
		$admin = $current->isAdmin();
		$connect = $current->isConnect();
		$send = $current->isSendEmail();
		
		$email = htmlspecialchars($current->getEmail());
		
		$sl = array_key_exists($id, $selected);
		$ch = $sl ? 'checked' : '';
		
		$checkbox = "<input type=\"checkbox\" name=\"selected[]\" value=\"{$id}\" {$ch}  >";
		
?>
		<tr class="<?php echo $class; ?>">
			<td><div align="center"><?php echo $checkbox; ?></div></td>
			<td><?php echo $name; ?></td>
			<td><a href="javascript: triggeredit('<?php echo $id; ?>', 'edit');"><?php echo $login; ?></a></td>
			<td class="<?php echo $connect ? "yes" : "no"; ?>"><div align="center"><?php echo $connect ? "Yes" : "No"; ?></div></td>
			<td class="<?php echo $admin ? "yes" : "no"; ?>"><div align="center"><?php echo $admin ? "Yes" : "No"; ?></div></td>
			<td><?php echo $email; ?></td>
			<td class="<?php echo $send ? "yes" : "no"; ?>"><div align="center"><?php echo $send ? "Yes" : "No"; ?></div></td>
			<td><div align="center"><a href="javascript: triggeredit('<?php echo $id; ?>', 'chpass');">change</a></div></td>
		</tr>
<?php
	} 
?>
		<tr>
			<td colspan="4">&nbsp;</td>
			<td colspan="4">
				<input type="submit" name="Submit" value="Add" onclick="triggerform('add')">
				<input type="submit" name="Submit" value="Remove" onclick="triggerform('remove')">
			</td>
		</tr>
	</tbody>
</table>
</form>
<?php
	$footer = new Footer();
	$footer->render();
?>
